#ifndef INC_H
#define INC_H

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>

extern "C" {
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
}

#if LUA_VERSION_NUM < 502
	# define lua_rawlen lua_objlen
	# define lua_getuservalue lua_getfenv
	# define lua_setuservalue lua_setfenv
	# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
	# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
	# define lua_resume(L,F,n) lua_resume(L,n)
	# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)

#elif LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM <= 504
	#define luaL_register(L,name,funcs) lua_newtable(L);luaL_setfuncs(L,funcs,0)
	#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
	#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
	#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
#else
	#error unsupported Lua version
#endif

#endif